package com.flyan.game.motafx.entity.animate;

import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.entity.Entity;
import com.almasb.fxgl.entity.EntityFactory;
import com.almasb.fxgl.entity.SpawnData;
import com.almasb.fxgl.entity.Spawns;
import com.almasb.fxgl.texture.AnimationChannel;
import com.flyan.game.motafx.component.BackpackComponent;
import com.flyan.game.motafx.component.character.BraveComponent;
import com.flyan.game.motafx.core.enums.EntityTypeEnum;
import javafx.animation.Animation;
import javafx.animation.FadeTransition;
import javafx.animation.ParallelTransition;
import javafx.animation.ScaleTransition;
import javafx.scene.image.ImageView;
import javafx.util.Duration;

import static com.almasb.fxgl.dsl.FXGL.entityBuilder;

/**
 * 动画实体工厂
 *
 * @author flyan
 * @version 1.0
 * @email flyan_by_chenu@sina.com
 * @since 2025/2/5
 */
public class AnimateEntityFactory implements EntityFactory {

    @Spawns("ANIMATE_ATTACK")
    public Entity attackAnimate(SpawnData data) {
        ImageView imageView = new ImageView(FXGL.image("materials/attack.png"));
        ScaleTransition st = new ScaleTransition(Duration.seconds(0.25), imageView);
        st.setToX(0.5);
        st.setToY(0.5);

        FadeTransition ft = new FadeTransition(Duration.seconds(0.25), imageView);
        ft.setToValue(0.1);

        ParallelTransition pt = new ParallelTransition(st, ft);
        pt.setCycleCount(Animation.INDEFINITE); // 重复播放
        pt.play();

        return entityBuilder(data)
                .type(EntityTypeEnum.ANIMATE_ATTACK)
                .view(imageView)
                .zIndex(EntityTypeEnum.ANIMATE_ATTACK.getZIndex().getIndex())
                .build();
    }

}
